<?php 
include 'inc/reuse/dbconfig.php';
$sql = "SELECT * FROM products GROUP BY fix_sub_products_type_id ORDER BY products_id DESC limit 12";
$rsd = mysql_query($sql);
$numOfRow = mysql_num_rows($rsd);
$dirname = "images/uploads/";
$td_images = "";
$td_name = "";
$data = "";
$count = 1;
while($row = mysql_fetch_array($rsd)){
	//เก็บข้อมูล ลชื่อสินค้า และ รุปภาพสินค้า
	$images_dir = $dirname.$row['products_id'];
	if(is_dir($images_dir))
	{
		$images = scandir($images_dir);
		$ignore = Array(".", "..",".svn", "otherfiletoignore");
		foreach($images as $curimg){
			if(!in_array($curimg, $ignore)) {
				$td_images .= "<td valign=\"top\">
									<div id=\"product-border\">
				                    	<a href=\"products_detail.php?products_id=".$row['products_id']."\" target=\"_blank\"><img src=\"$images_dir/$curimg\"  /> </a> 
				                        <div class=\"product-detail\"><p><a href=\"products_detail.php?products_id=".$row['products_id']."\" target=\"_blank\">".$row['products_name']."</a></p></div>
					               </div>
							   </td>";
				break;
				//<a href=\"products_detail.php?products_id=".$row['products_id']."\" target=\"_blank\"><img src=\"$images_dir/$curimg\" width=\"150\" height=\"200\"></a>
			}
		}
	}
	if($count % 3 == 0 || $count == $numOfRow)
	{
		$data .= "<tr valign=\"top\">$td_images</tr>";
		$td_images = "";
	}	
	//echo $count.",".$numOfRow;
	$count++;
}

echo $data;
?>